package com.lx.common.vo;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * Created by Administrator on 2018/5/26 0026.
 */
public class Message<T> {
    final public static int CODE_SUCCESS = 666;
    final public static int CODE_FAIL = 555;

    private int code;
    private String msg;
    private T data;

    public static <T> Message<T> ok(T t){
        return new Message<T>(CODE_SUCCESS,t);
    }
    public static <T> Message<T> ok(String msg){
        return new Message<T>(CODE_SUCCESS,msg);
    }
    public static <T> Message<T> ok(String msg,T t){
        return new Message<T>(CODE_SUCCESS,msg,t);
    }
    public static <T> Message<T> fail(String message){
        return new Message<T>(CODE_FAIL,message);
    }

    public Message(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public Message(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Message(int code) {
        this.code = code;
    }

    private Message(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    private Message() {
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);

    }
}
